/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.edu.nju.software.login.service;

import cn.edu.nju.software.login.DAO.UserDAO;
import cn.edu.nju.software.login.domain.User;
import cn.edu.nju.software.login.factory.DAOFactory;

/**
 *
 * @author han
 */
public class UserService {
    
    public boolean isLogin(String userName, String password){
        UserDAO userDAO = DAOFactory.getUserDAOInstance();
        User user = userDAO.get(userName);
        
        //判断该用户名是否存在
        if(user != null){
            //判断用户名对应的用户的密码是否与传进来的密码一致
            if(user.getPassword().equals(password) ){
                return true;
            }else{
                return false;
            }
        }else{  //如用户名不存在直接返回登录失败
            return false;
        }
    }
    
    public void addUser(User user){
        UserDAO userDAO = DAOFactory.getUserDAOInstance();
        userDAO.save(user);
    }
}
